home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sr / info.lha / info-sr.1992 / 000019_eric@cs.sfu.ca _Thu Nov 19 14:27:36 1992.msg < prev    next >
Text File  |  1993-07-24  |  8KB  |  315 lines

  1. Received: from aquarius.cs.sfu.ca by optima.cs.arizona.edu (5.65c/15) via SMTP
  2.     id AA17906; Thu, 19 Nov 1992 15:29:07 MST
  3. Received: by aquarius.cs.sfu.ca id AA27946
  4.   (5.65c/IDA-1.4.4 for info-sr@cs.arizona.edu); Thu, 19 Nov 1992 14:27:36 -0800
  5. Date: Thu, 19 Nov 1992 14:27:36 -0800
  6. From: Eric Kolotyluk <eric@cs.sfu.ca>
  7. Message-Id: <199211192227.AA27946@aquarius.cs.sfu.ca>
  8. To: info-sr@cs.arizona.edu
  9. Subject: Priorities in SR
  10.  
  11. I'm working on an SR program to simulate the interaction of a disk,
  12. disk controller, and computer system.  I started off using the Discrete
  13. Event Simulation example program in Chapter 18 od the SR Programming
  14. Language book.  I wasn't very happy with the implementation of the
  15. Scheduler because of having to keep track of active processes, etc.
  16.  
  17. When I realized that the sole point of keeping track of active
  18. processes was to lock-out the Scheduler while other tasks were still
  19. ready to run, I felt the same effect could be achieved by simply running
  20. the Scheduler at a lower process priority than every other process in
  21. the program.
  22.  
  23. I reworked my program to explicitly set the scheduler's priority lower
  24. than everything else, but it has only partially the desired effect.  In
  25. particular I think I'm seeing a situation where the scheduler is still
  26. running when other processes of higher priority are definitely `ready'.
  27.  
  28. Could someone please tell me if this a `bug' in SR's dispatching
  29. mechanisms or a misunderstanding on how I read the description in the
  30. book.
  31.  
  32. What follows is a copy of the program and some sample output.  The point
  33. where I think something is wrong is right after the main resource starts
  34. up a couple of tasks.  Each task calls scheduler.delay and the delay proc
  35. registers both of these.  At this point control should transfer back to
  36. the main resource so it can call delay, but in fact the event_manager
  37. in the scheduler imediately processes its event list...   This should
  38. not happen if the scheduler is `really' running at a lower priority than
  39. the main process.
  40.  
  41. A further troubling point in the example output below suggests that the
  42. task with the largest delay gets the first go_ahead???
  43.  
  44. ./disk
  45. main:       my priority = 1
  46. event_manager:  my priority = 0
  47. controller: my priority = 1
  48. main: creating tasks...
  49. task: my priority = 1
  50. scheduler: delay = 0.00000 9524.97 9524.97
  51. Task 1 created.
  52. task: my priority = 1
  53. scheduler: delay = 0.00000 3077.64 3077.64
  54. event_manager: go ahead 9524.97
  55. event_manager: go ahead 3077.64
  56. Task 2 created.
  57. scheduler: delay = 3077.64 1.00000e+08 1.00003e+08
  58. event_manager: go ahead 1.00003e+08
  59. disk seek to cylinder 564
  60. scheduler: delay = 1.00003e+08 1575.00 1.00005e+08
  61. main: shutting down
  62. event_manager: go ahead 1.00005e+08
  63. disk seek to cylinder 1092
  64. scheduler: delay = 1.00005e+08 1645.21 1.00006e+08
  65. scheduler: delay = 1.00005e+08 9938.55 1.00015e+08
  66. event_manager: go ahead 1.00006e+08
  67. event_manager: go ahead 1.00015e+08
  68. Controller: disk_manager shutting down
  69. scheduler: delay = 1.00015e+08 31.9262 1.00015e+08
  70. event_manager: go ahead 1.00015e+08
  71. Scheduler: event_manager shutting down
  72. RTS warning: blocked process: Task.task
  73. RTS warning: blocked process: Task.task
  74.  
  75. #########################################################################
  76. #                                    #
  77. #    Disk Simulation Program                        #
  78. #                                    #
  79. #########################################################################
  80.  
  81. global System
  82.  
  83.    import Scheduler, Controller
  84.  
  85.    const tasks := 2
  86.  
  87.    var scheduler:   cap Scheduler
  88.    var controller1: cap Controller
  89.    var active_tasks: int := tasks
  90.  
  91. end System
  92.  
  93. #########################################################################
  94. #                                    #
  95. #    Scheduler resource                        #
  96. #                                    #
  97. #########################################################################
  98.  
  99. resource Scheduler
  100.  
  101.   op time() returns t: real
  102.   op delay(t: real)
  103.   op shutdown()
  104.  
  105.   import System
  106.  
  107. body Scheduler()
  108.  
  109.    op event_list(go_ahead: cap(); t: real)
  110.  
  111.    var clock  := 0.0    # the simulation clock
  112.  
  113.    process event_manager
  114.  
  115.       var priority: int
  116.       setpriority(-1)
  117.       priority := mypriority()
  118.       write("event_manager:  my priority =", priority)
  119.  
  120.       do true ->
  121.      in time() returns t ->
  122.         t := clock
  123.  
  124.      [] event_list(go_ahead,t) by t ->
  125.         clock := t
  126.         write("event_manager: go ahead", t)
  127.         send go_ahead()
  128.         setpriority(-1)
  129.  
  130.      [] shutdown() ->
  131.         exit
  132.      ni
  133.       od
  134.  
  135.       write("Scheduler: event_manager shutting down")
  136.  
  137.    end event_manager
  138.  
  139.    # provide a simple call interface for processors
  140.    proc delay(t)
  141.       write("scheduler: delay =", clock, t, clock+t)
  142.       op go_ahead()
  143.       send event_list(go_ahead, t+clock)
  144.       receive go_ahead()
  145.    end
  146.  
  147. end Scheduler
  148.  
  149. #########################################################################
  150. #                                    #
  151. #    Disk resource                            #
  152. #                                    #
  153. #########################################################################
  154. #
  155. # The Disk resource simulates a raw disk drive in terms of seek time and
  156. # rotational latency.
  157.  
  158. resource Disk
  159.  
  160.    op seek(cyl: int), read(sec: int)
  161.  
  162.    import System
  163.  
  164. body Disk(
  165.    cylinders:    int;
  166.    tracks:    int; 
  167.    sectors:    int;
  168.    bytes:    int;
  169.    rpm:        real;
  170.    seekMin:    real;
  171.    seekAvg:    real;
  172.    seekMax:    real)
  173.  
  174.    var cylinder: int  := 0    /* Current cylinder position (0 = outermost) */
  175.    var theta:     real := 0.0    /* Current Angle of the disk platters */
  176.    var velocity: real := cylinders / (seekMax - seekMin)
  177.  
  178.    proc seek(cyl)
  179.  
  180.       var distance: int := abs(cylinder - cyl)
  181.  
  182.       write("disk seek to cylinder", cyl)
  183.  
  184.       scheduler.delay( distance * velocity + seekMin )
  185.  
  186.    end seek
  187.  
  188.    proc read(sec)
  189.  
  190.    end read
  191.  
  192. end Disk
  193.  
  194. #########################################################################
  195. #                                    #
  196. #    Controller resource                        #
  197. #                                    #
  198. #########################################################################
  199.  
  200. resource Controller
  201.  
  202.    op blocks() returns highest_block: int
  203.    op block_request(block: int)
  204.    op shutdown()
  205.  
  206.    import System, Disk
  207.  
  208. body Controller()
  209.  
  210.    var disk: cap Disk
  211.  
  212.    disk := create Disk(2460, 15, 66, 512, 5400, 1500, 10000, 20000)
  213.  
  214.    proc blocks() returns highest_block
  215.  
  216.       highest_block := 2460 * 15 * 66 - 1
  217.  
  218.    end blocks
  219.  
  220.    process disk_manager
  221.  
  222.       var priority: int
  223.       priority := mypriority()
  224.       write("controller: my priority =", priority)
  225.  
  226.       do true ->
  227.      in block_request(block) ->
  228.  
  229.         disk.seek(block / 15 / 66)
  230.  
  231.      [] shutdown() ->
  232.         exit
  233.  
  234.      ni
  235.       od
  236.  
  237.       write("Controller: disk_manager shutting down")
  238.  
  239.    end disk_manager
  240.  
  241. end Controller
  242.  
  243. #########################################################################
  244. #                                    #
  245. #    Task resource                            #
  246. #                                    #
  247. #########################################################################
  248.  
  249. resource Task
  250.  
  251.    import System, Controller
  252.  
  253. body Task(accesses: int)
  254.  
  255.    var cblocks: int := controller1.blocks()
  256.  
  257.    process task
  258.  
  259.       var priority: int
  260.       priority := mypriority()
  261.       write("task: my priority =", priority)
  262.  
  263.       fa f := 1 to accesses ->
  264.  
  265.      scheduler.delay(random(10000.0))
  266.  
  267.      controller1.block_request(int(random(cblocks)))
  268.  
  269.       af
  270.  
  271.       --active_tasks
  272.  
  273.    end task
  274.  
  275. end Task
  276.  
  277. #########################################################################
  278. #                                    #
  279. #    main resource                            #
  280. #                                    #
  281. #########################################################################
  282.  
  283. resource main()
  284.  
  285.    import System, Scheduler, Controller, Task
  286.  
  287.    const stime: int := 100000000    # Simulation Time, 100 Seconds
  288.  
  289.    var task[tasks]: cap Task
  290.    var i: int
  291.    var priority: int
  292.  
  293.    priority := mypriority()
  294.    write("main:       my priority =", priority)
  295.  
  296.    scheduler   := create Scheduler()
  297.    controller1 := create Controller()
  298.  
  299.    write("main: creating tasks...")
  300.  
  301.    fa i := 1 to tasks ->
  302.  
  303.       task[i] := create Task(10)
  304.       write("Task", i, "created.")
  305.  
  306.    af
  307.  
  308.    scheduler.delay(stime)
  309.    write("main: shutting down")
  310.  
  311.    controller1.shutdown()
  312.    scheduler.shutdown()
  313.  
  314. end main
  315.